/*
 * 作者：姚俊
 * 功能：忘记密码的处理
 * 日期：2015-06-12
 */
package admin.action.baseInfo;

import java.io.IOException;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import admin.email.SendEmail;
import admin.service.member.TeacherService;
import teacher.bean.Teacher;
import teacher.service.teacher;
import tools.RandomCreateNum;

public class ForgetPassAction {
	
	private Teacher teacher1;
	private String flag;

	
	public Teacher getTeacher1() {
		return teacher1;
	}

	public void setTeacher1(Teacher teacher1) {
		this.teacher1 = teacher1;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public String execute()
	{
		if(new TeacherService().CheckUserAndName(this.teacher1))
		{
			Teacher tea=new Teacher();
			tea.setPassword(String.valueOf(RandomCreateNum.createNum(6)));
			tea.setUser(this.getTeacher1().getUser());
			new TeacherService().mendTeacherPass(tea);
			
			this.setTeacher1(new teacher().SelectTeacher(this.teacher1));
			//发送邮件
			try {
				SendEmail.send_email(this.getTeacher1().getMail(), "找回密码","动态密码为："+this.getTeacher1().getPassword());
			} catch (AddressException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (MessagingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			this.setFlag("succ");
		}
		else
		{
			this.setFlag("err");
		}
		return "succ";
	}

}
